import static java.lang.Math.*;

/**
 * Created by suhuang on 17-4-19.
 */
public class complex {
    public static void main (String[] args) {
        Complex b = new Complex(2,5);
        Complex c = new Complex(3,-4);
        System.out.println(b + "+" + c + "=" + b.ComplexAdd(c));
        System.out.println(b + "-" + c + "=" + b.ComplexSub(c));
        System.out.println(b + "*" + c + "=" + b.ComplexMulit(c));
        System.out.println(b + "/" + c + "=" + b.ComplexDiv(c));

    }
}
class Complex {
    private double R;
    private double I;
    public Complex (double R, double I){
        this.R=R;
        this.I=I;
    }
    public Complex ComplexAdd(Complex a){

        return new Complex(R + a.R, I + a.I);
    }
    public Complex ComplexSub(Complex a){

        return new Complex (R - a.R, I - a.I);
    }
    public Complex ComplexMulit(Complex a){

        return new Complex (R*a.R-I*a.I, R*a.I + I*a.R);
    }
    public Complex ComplexDiv(Complex a){
        double d = sqrt(a.R*a.R)+ sqrt(a.I*a.I);
        double e = (R * a.I - I * a.R);
        return new Complex((R * a.R + I * a.I) / d, round(e / d));
    }
    public String toString(){
        String rtr_str ="";
        if(I>0)
            rtr_str = "("+R+"+"+I+"i"+")";
        if (I==0) {
            rtr_str = "(" + R + ")";
        }
        if (I<0){
            rtr_str = "(" + R + I + "i" + ")";
        }
        return rtr_str;
    }
}
